package com.esri.core.geometry;

import com.esri.core.geometry.Geometry;
import com.github.mikephil.charting.utils.Utils;
import java.io.IOException;
import org.codehaus.jackson.JsonParseException;
import org.codehaus.jackson.JsonParser;
import org.codehaus.jackson.JsonToken;

/* loaded from: classes.dex */
class OperatorImportFromJsonCursor extends MapGeometryCursor {
    static final /* synthetic */ boolean d = true;
    JsonParserCursor a;
    int b;
    int c = -1;

    public OperatorImportFromJsonCursor(int i, JsonParserCursor jsonParserCursor) {
        if (jsonParserCursor == null) {
            throw new IllegalArgumentException();
        }
        this.b = i;
        this.a = jsonParserCursor;
    }

    @Override // com.esri.core.geometry.MapGeometryCursor
    public int getGeometryID() {
        return this.c;
    }

    @Override // com.esri.core.geometry.MapGeometryCursor
    public MapGeometry next() {
        JsonParser next = this.a.next();
        if (next != null) {
            this.c = this.a.getID();
            return a(this.b, next);
        }
        return null;
    }

    /* JADX WARN: Code restructure failed: missing block: B:106:0x01b8, code lost:
        if (r2 != "zmin") goto L99;
     */
    /* JADX WARN: Code restructure failed: missing block: B:107:0x01ba, code lost:
        if (r54 == 0) goto L98;
     */
    /* JADX WARN: Code restructure failed: missing block: B:108:0x01bc, code lost:
        if (r54 != 3077) goto L43;
     */
    /* JADX WARN: Code restructure failed: missing block: B:109:0x01be, code lost:
        r23 = b(r55);
        r11 = r52;
        r47 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:118:0x01e4, code lost:
        if (r2 != "ymax") goto L87;
     */
    /* JADX WARN: Code restructure failed: missing block: B:119:0x01e6, code lost:
        if (r54 == 0) goto L86;
     */
    /* JADX WARN: Code restructure failed: missing block: B:120:0x01e8, code lost:
        if (r54 != 3077) goto L55;
     */
    /* JADX WARN: Code restructure failed: missing block: B:121:0x01ea, code lost:
        r20 = b(r55);
        r11 = r52;
        r46 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:130:0x0210, code lost:
        if (r2 != "zmax") goto L75;
     */
    /* JADX WARN: Code restructure failed: missing block: B:131:0x0212, code lost:
        if (r54 == 0) goto L74;
     */
    /* JADX WARN: Code restructure failed: missing block: B:132:0x0214, code lost:
        if (r54 != 3077) goto L67;
     */
    /* JADX WARN: Code restructure failed: missing block: B:133:0x0216, code lost:
        r25 = b(r55);
        r11 = r52;
        r48 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:47:0x0105, code lost:
        if (r2 != "paths") goto L203;
     */
    /* JADX WARN: Code restructure failed: missing block: B:48:0x0107, code lost:
        if (r54 == 0) goto L202;
     */
    /* JADX WARN: Code restructure failed: missing block: B:50:0x010b, code lost:
        if (r54 != 25607) goto L162;
     */
    /* JADX WARN: Code restructure failed: missing block: B:51:0x010d, code lost:
        r37 = a(false, r55, r3, r4);
        r11 = r52;
        r14 = true;
     */
    /* JADX WARN: Code restructure failed: missing block: B:94:0x018c, code lost:
        if (r2 != "ymin") goto L111;
     */
    /* JADX WARN: Code restructure failed: missing block: B:95:0x018e, code lost:
        if (r54 == 0) goto L110;
     */
    /* JADX WARN: Code restructure failed: missing block: B:96:0x0190, code lost:
        if (r54 != 3077) goto L31;
     */
    /* JADX WARN: Code restructure failed: missing block: B:97:0x0192, code lost:
        r16 = b(r55);
        r11 = r52;
        r43 = true;
     */
    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r37v0 */
    /* JADX WARN: Type inference failed for: r37v1 */
    /* JADX WARN: Type inference failed for: r37v2, types: [com.esri.core.geometry.Envelope] */
    /* JADX WARN: Type inference failed for: r37v3 */
    /* JADX WARN: Type inference failed for: r37v4, types: [com.esri.core.geometry.Geometry] */
    /* JADX WARN: Type inference failed for: r37v5, types: [com.esri.core.geometry.Geometry] */
    /* JADX WARN: Type inference failed for: r37v6, types: [com.esri.core.geometry.Geometry] */
    /* JADX WARN: Type inference failed for: r37v7 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    private static com.esri.core.geometry.MapGeometry a(int r54, org.codehaus.jackson.JsonParser r55) {
        /*
            Method dump skipped, instructions count: 758
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: com.esri.core.geometry.OperatorImportFromJsonCursor.a(int, org.codehaus.jackson.JsonParser):com.esri.core.geometry.MapGeometry");
    }

    public static MapGeometry fromJsonToUnknown(JsonParser jsonParser) throws Exception {
        return a(0, jsonParser);
    }

    public static MapGeometry fromJsonToEnvelope(JsonParser jsonParser) throws Exception {
        return a(Geometry.GeometryType.Envelope, jsonParser);
    }

    public static MapGeometry fromJsonToPoint(JsonParser jsonParser) throws Exception {
        return a(513, jsonParser);
    }

    public static MapGeometry fromJsonToPolygon(JsonParser jsonParser) throws Exception {
        return a(Geometry.GeometryType.Polygon, jsonParser);
    }

    public static MapGeometry fromJsonToPolyline(JsonParser jsonParser) throws Exception {
        return a(Geometry.GeometryType.Polyline, jsonParser);
    }

    public static MapGeometry fromJsonToMultiPoint(JsonParser jsonParser) throws Exception {
        return a(Geometry.GeometryType.MultiPoint, jsonParser);
    }

    private static void a(JsonParser jsonParser) throws IOException, JsonParseException {
        jsonParser.skipChildren();
    }

    private static double b(JsonParser jsonParser) throws IOException, JsonParseException {
        if (jsonParser.getCurrentToken() == JsonToken.VALUE_NULL || (jsonParser.getCurrentToken() == JsonToken.VALUE_STRING && jsonParser.getCurrentName() == "NaN")) {
            return NumberUtils.NaN();
        }
        return jsonParser.getValueAsDouble();
    }

    private static Geometry a(JsonParser jsonParser, AttributeStreamOfDbl attributeStreamOfDbl, AttributeStreamOfDbl attributeStreamOfDbl2) throws Exception {
        if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
            throw new GeometryException("failed to parse multipoint: array of vertices is expected");
        }
        MultiPoint multiPoint = new MultiPoint();
        AttributeStreamOfDbl attributeStreamOfDbl3 = (AttributeStreamOfDbl) AttributeStreamBase.createDoubleStream(2, Utils.DOUBLE_EPSILON);
        double[] dArr = new double[4];
        int i = 0;
        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
            if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
                throw new GeometryException("failed to parse multipoint: array is expected, multipoint vertices consist of arrays of cooridinates");
            }
            int i2 = 0;
            while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                dArr[i2] = b(jsonParser);
                i2++;
            }
            if (i2 < 2) {
                throw new GeometryException("failed to parse multipoint: each vertex array has to have at least 2 elements");
            }
            int i3 = i * 2;
            if (attributeStreamOfDbl3.size() == i3) {
                int i4 = i * 3;
                if (i4 % 2 != 0) {
                    i4++;
                }
                attributeStreamOfDbl3.resize(i4);
            }
            attributeStreamOfDbl3.write(i3, dArr[0]);
            attributeStreamOfDbl3.write(i3 + 1, dArr[1]);
            int i5 = 16;
            if (attributeStreamOfDbl.size() == i) {
                int i6 = (i * 3) / 2;
                if (i6 < 4) {
                    i6 = 4;
                } else if (i6 < 16) {
                    i6 = 16;
                }
                attributeStreamOfDbl.resize(i6);
            }
            if (i2 > 2) {
                attributeStreamOfDbl.write(i, dArr[2]);
            } else {
                attributeStreamOfDbl.write(i, NumberUtils.NaN());
            }
            if (attributeStreamOfDbl2.size() == i) {
                int i7 = (i * 3) / 2;
                if (i7 < 4) {
                    i5 = 4;
                } else if (i7 >= 16) {
                    i5 = i7;
                }
                attributeStreamOfDbl2.resize(i5);
            }
            if (i2 > 3) {
                attributeStreamOfDbl2.write(i, dArr[3]);
            } else {
                attributeStreamOfDbl2.write(i, NumberUtils.NaN());
            }
            i++;
        }
        if (i != 0) {
            MultiPointImpl multiPointImpl = (MultiPointImpl) multiPoint._getImpl();
            multiPointImpl.resize(i);
            multiPointImpl.setAttributeStreamRef(0, attributeStreamOfDbl3);
        }
        return multiPoint;
    }

    private static Geometry a(boolean z, JsonParser jsonParser, AttributeStreamOfDbl attributeStreamOfDbl, AttributeStreamOfDbl attributeStreamOfDbl2) throws Exception {
        Geometry polyline;
        int i;
        Geometry geometry;
        int i2;
        AttributeStreamOfDbl attributeStreamOfDbl3;
        AttributeStreamOfInt8 attributeStreamOfInt8;
        int i3;
        if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
            throw new GeometryException("failed to parse multipath: array of array of vertices is expected");
        }
        if (z) {
            polyline = new Polygon();
        } else {
            polyline = new Polyline();
        }
        AttributeStreamOfInt32 attributeStreamOfInt32 = (AttributeStreamOfInt32) AttributeStreamBase.createIndexStream(0);
        AttributeStreamOfDbl attributeStreamOfDbl4 = (AttributeStreamOfDbl) AttributeStreamBase.createDoubleStream(2, Utils.DOUBLE_EPSILON);
        AttributeStreamOfInt8 attributeStreamOfInt82 = (AttributeStreamOfInt8) AttributeStreamBase.createByteStream(0);
        double[] dArr = new double[4];
        double[] dArr2 = new double[4];
        int i4 = z ? 3 : 2;
        int i5 = 0;
        int i6 = 0;
        while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
            if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
                throw new GeometryException("failed to parse multipath: ring/path array is expected");
            }
            jsonParser.nextToken();
            int i7 = 0;
            int i8 = 0;
            int i9 = 0;
            boolean z2 = true;
            while (jsonParser.getCurrentToken() != JsonToken.END_ARRAY) {
                if (jsonParser.getCurrentToken() != JsonToken.START_ARRAY) {
                    throw new GeometryException("failed to parse multipath: array is expected, rings/paths vertices consist of arrays of cooridinates");
                }
                int i10 = 0;
                while (jsonParser.nextToken() != JsonToken.END_ARRAY) {
                    dArr[i10] = b(jsonParser);
                    i10++;
                }
                if (i10 < 2) {
                    throw new GeometryException("failed to parse multipath: each vertex array has to have at least 2 elements");
                }
                jsonParser.nextToken();
                while (true) {
                    int i11 = i5 * 2;
                    if (attributeStreamOfDbl4.size() == i11) {
                        int i12 = i5 * 3;
                        if (i12 % 2 != 0) {
                            i12++;
                        }
                        geometry = polyline;
                        if (i12 < 8) {
                            i12 = 8;
                        } else if (i12 < 32) {
                            i12 = 32;
                        }
                        attributeStreamOfDbl4.resize(i12);
                    } else {
                        geometry = polyline;
                    }
                    int i13 = i7;
                    int i14 = i4;
                    attributeStreamOfDbl4.write(i11, dArr[0]);
                    attributeStreamOfDbl4.write(i11 + 1, dArr[1]);
                    int i15 = 16;
                    if (attributeStreamOfDbl.size() == i5) {
                        i2 = 2;
                        int i16 = (i5 * 3) / 2;
                        if (i16 < 4) {
                            i16 = 4;
                        } else if (i16 < 16) {
                            i16 = 16;
                        }
                        attributeStreamOfDbl.resize(i16);
                    } else {
                        i2 = 2;
                    }
                    if (i10 > i2) {
                        attributeStreamOfDbl3 = attributeStreamOfDbl4;
                        attributeStreamOfInt8 = attributeStreamOfInt82;
                        attributeStreamOfDbl.write(i5, dArr[i2]);
                    } else {
                        attributeStreamOfDbl3 = attributeStreamOfDbl4;
                        attributeStreamOfInt8 = attributeStreamOfInt82;
                        attributeStreamOfDbl.write(i5, NumberUtils.NaN());
                    }
                    if (attributeStreamOfDbl2.size() == i5) {
                        int i17 = (i5 * 3) / i2;
                        if (i17 < 4) {
                            i15 = 4;
                        } else if (i17 >= 16) {
                            i15 = i17;
                        }
                        attributeStreamOfDbl2.resize(i15);
                    }
                    if (i10 > 3) {
                        i3 = i14;
                        attributeStreamOfDbl2.write(i5, dArr[3]);
                    } else {
                        i3 = i14;
                        attributeStreamOfDbl2.write(i5, NumberUtils.NaN());
                    }
                    if (z2) {
                        i6++;
                        attributeStreamOfInt32.add(i5);
                        attributeStreamOfInt82 = attributeStreamOfInt8;
                        attributeStreamOfInt82.add(z ? (byte) 1 : (byte) 0);
                        dArr2[0] = dArr[0];
                        dArr2[1] = dArr[1];
                        dArr2[2] = dArr[2];
                        dArr2[3] = dArr[3];
                        i9 = i10;
                        z2 = false;
                    } else {
                        attributeStreamOfInt82 = attributeStreamOfInt8;
                    }
                    i5++;
                    i7 = i13 + 1;
                    if (i7 < i3 && jsonParser.getCurrentToken() == JsonToken.END_ARRAY) {
                        attributeStreamOfDbl4 = attributeStreamOfDbl3;
                        i4 = i3;
                        polyline = geometry;
                    }
                }
                attributeStreamOfDbl4 = attributeStreamOfDbl3;
                i8 = i10;
                i4 = i3;
                polyline = geometry;
            }
            Geometry geometry2 = polyline;
            AttributeStreamOfDbl attributeStreamOfDbl5 = attributeStreamOfDbl4;
            int i18 = i4;
            if (z && i7 > i18 && i8 == i9 && dArr2[0] == dArr[0] && dArr2[1] == dArr[1]) {
                if (dArr2[2] == dArr[2]) {
                    if (dArr2[3] == dArr[3]) {
                        i5--;
                        int i19 = i7 - 1;
                    }
                    attributeStreamOfDbl4 = attributeStreamOfDbl5;
                    i4 = i18;
                    polyline = geometry2;
                }
            }
            attributeStreamOfDbl4 = attributeStreamOfDbl5;
            i4 = i18;
            polyline = geometry2;
        }
        Geometry geometry3 = polyline;
        AttributeStreamOfDbl attributeStreamOfDbl6 = attributeStreamOfDbl4;
        if (i5 != 0) {
            attributeStreamOfInt32.resize(i6);
            attributeStreamOfInt82.resize(i6);
            if (i5 > 0) {
                attributeStreamOfInt32.add(i5);
                i = 0;
                attributeStreamOfInt82.add((byte) 0);
            } else {
                i = 0;
            }
            MultiPathImpl multiPathImpl = (MultiPathImpl) geometry3._getImpl();
            multiPathImpl.setAttributeStreamRef(i, attributeStreamOfDbl6);
            multiPathImpl.setPathFlagsStreamRef(attributeStreamOfInt82);
            multiPathImpl.setPathStreamRef(attributeStreamOfInt32);
        }
        return geometry3;
    }
}
